# -*- coding: utf-8 -*-

# @Project : UI_DDTFrameWork
# @Author  : Mr.Deng
# @Time    : 2021/9/18 22:37

"""
截图，默认错误截图保存位置
"""

from common.seleniumLibrary.base import Base
from common.tools.timeTools import TimeTools
from common.tools.decorator import error_collection
from config.filePathConfig import errorPicturePath

fileName = errorPicturePath + TimeTools.get_now_date("%Y%m%d%H%M%S") + ".png"


class ScreenShot(Base):

    @error_collection
    def screen_shot(self, filename: str = fileName):
        """
        截图
        :param filename: 图片保存位置，默认错误截图
        :return:
        """
        try:
            self.driver.get_screenshot_as_file(filename=filename)
        except:
            raise Exception("截图失败！！！")
        self.Log.info(f"截图保存到文件：{filename}")


# if __name__ == '__main__':
#     from selenium.webdriver.common.by import By
#
#     element = ScreenShot()
#     element.open_url("http://www.baidu.com")
#     element.screen_shot()
